# here put the import lib
# @Time : 2020/8/30 21:31
# @Author : liruiyang
# @File : UserMinModel
# @Software: PyCharm
from ..service.userInfoManager import UserInfoManager
from ..utils.response_code import RET


class UserMin:
    def __init__(self, user_id, user_name, email, user_type):
        self.user_id = user_id
        self.user_name = user_name
        self.mail = email
        self.userType = user_type

    @property
    def is_authenticated(self):
        return True

    @property
    def is_active(self):
        return True

    @property
    def is_anonymous(self):
        return False

    def get_id(self):
        return str(self.user_id)

    @classmethod
    def get(cls, user_id):
        result_dict = UserInfoManager.get_user(user_id)
        user_info = result_dict.get("data")
        if result_dict.get("code") == '200':
            user = UserMin(user_id=user_info.userID, user_name=user_info.userName, email=user_info.mail,
                           user_type=user_info.userType)
            return {"code": RET.OK, 'data': user}

        return result_dict
